<template>
  <div class="price-table-container">
    <el-table
      v-loading="loading"
      :data="priceList"
      border
      stripe
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="60" align="center" />
      <el-table-column label="价格日期" align="center" prop="priceDate" />
      <el-table-column label="铝价金额(元)" align="center" prop="averagePrice" />
      <el-table-column label="数据来源" align="center" prop="priceSource">
        <template slot-scope="scope">
          <el-tag :type="scope.row.priceSource === 'shanghai' ? 'success' : 'warning'">
            {{ scope.row.priceSource === 'shanghai' ? '上海铝价' : '长江铝价' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedAt" />
      <el-table-column label="创建时间" align="center" prop="createdAt" />
      <el-table-column label="手动更新" align="center" prop="manualUpdate">
        <template slot-scope="scope">
          <el-tag :type="scope.row.manualUpdate ? 'danger' : 'info'">
            {{ scope.row.manualUpdate ? '是' : '否' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="$emit('edit', scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="$emit('delete', scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <!-- 分页区域 -->
    <div class="pagination-container" v-if="total > 0">
      <el-pagination
        background
        @size-change="$emit('size-change', $event)"
        @current-change="$emit('current-change', $event)"
        :current-page="currentPage"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AluminumPriceTable',
  props: {
    priceList: {
      type: Array,
      default: () => []
    },
    loading: {
      type: Boolean,
      default: false
    },
    total: {
      type: Number,
      default: 0
    },
    currentPage: {
      type: Number,
      default: 1
    },
    pageSize: {
      type: Number,
      default: 10
    },
    pageSizes: {
      type: Array,
      default: () => [3, 5, 10, 20, 50]
    }
  },
  methods: {
    handleSelectionChange(selection) {
      this.$emit('selection-change', selection);
    }
  }
}
</script> 